package com.yjtravel.observer.eventbus;

import java.util.concurrent.Executors;

/**
 * @author weiqi
 * @version 1.0
 * Create by 2024/7/11 9:40
 */
public class test {
    public static void main(String[] args) {
//        EventBus eventBus = new EventBus();// 阻塞的
        EventBus eventBus = new EventBus(Executors.newCachedThreadPool());//异步的
        eventBus.registry(new ObserverDemo());
        eventBus.post(1);
        System.out.println("哈哈");
    }

    private static class ObserverDemo{

        @Subscribe
        public void postStr(String event){
            System.out.println(event);
        }

//        @Subscribe
//        public void postStr1(String event, String event2){
//            System.out.println(event);
//        }

        @Subscribe
        public void postInt(Integer event){
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("Integer => " + event);
        }

        /**
         * 接收的object 默认会转成包装类，这里不会被执行
         * @param event
         */
        @Subscribe
        public void postint(int event){
            System.out.println("int => " + event);
        }
    }
}
